
import axios from 'axios'
import store from '@/vuex/store.js'
axios.defaults.baseURL='https://ms.dazhongmiaotuan.cn/index.php/'
//https://ms.dazhongmiaotuan.cn/index.php/
//http://xiaoyan.zhujiao.world
 function send_code(type,phone){
  axios.post('/api/send_code.html',{
    type:1,
    phone:phone
  }).then((res)=>{
    if(res.data.code==1){
      alert(res.data.msg);
    }else{
        alert("发送失败！");
    }
  }).catch((err)=>{
    console.log(err)
  })
}

 function login(code,phone,callback){
   return axios.post('/api/logining.html',{
    code:code,
    phone:phone
  }).then((res)=>{
     callback(res)
     //return res.data;
   }).catch((err)=>{
       console.log(err)
   })
}

 function getmenu_list(token){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/menu_list.html')
         .then(res => {
           return res.data.data;
         });
 }

   function getpermiss_list(token){
        axios.defaults.headers.common["token"] = token;
        return  axios.post('/api/permiss_list.html')
              .then(res => {
                return res.data;
              });
   }


//平台账户管理
function getaccount_list(token,keywords,page,size){
  axios.defaults.headers.common["token"] = token;
  return axios.post('/api/account_list.html',{
    keywords:keywords,
    page:page,
    size:size
  }).then(res => {
           return res.data;
         });
}

//编辑平台账户管理
function edit_account(data){
  axios.defaults.headers.common["token"]=data.token;
  return axios.post('/api/edit_account.html',{
    mobile:data.mobile,
    real_name:data.real_name,
    type:data.type,
    id:data.id,
    depar_id:data.depar_id,
    permiss_id:data.permiss_id
  }).then(res => {
        return res.data;
         });
}
//获取权限列表
function permiss_list(token){
  axios.defaults.headers.common["token"] = token;
  return axios.post('/api/permiss_list.html').then(res => {
           return res.data.data;
         });
}
//获取部门列表
function depar_list(token){
  axios.defaults.headers.common["token"] = token;
  return axios.post('/api/depar_list.html').then(res => {
           return res.data.data;
         });
}
//获取id
function account_info(token,id){
  axios.defaults.headers.common["token"] = token;
  return axios.post('/api/account_info.html',{
    id:id
  }).then(res => {
           return res.data.info;
         });
}

//添加账户
function add_account(data){
  axios.defaults.headers.common["token"] =data.token;
  return axios.post('/api/add_account.html',{
    mobile:data.mobile,
    real_name:data.real_name,
    type:data.type,
    depar_id:data.depar_id,
    permiss_id:data.permiss_id
  }).then(res => {
         return res.data;
         });
}

//客户信息变更记录
function getcustomer_change(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
   return axios.post('/api/staff/customer_change.html',{
     keywords:keywords,
     page:page,
     size:size
   }).then(res => {
            return res.data;
          });
}

//用户权限变更记录

function userpowers_change(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
   return axios.post('/api/staff/userpowers_change.html',{
     keywords:keywords,
     page:page,
     size:size
   }).then(res => {
            return res.data;
          });
}

//获取设置接口

function sys_config(token){
   axios.defaults.headers.common["token"] = token;
   return axios.post('/api/sys_config.html').then(res => {
            return res.data.info;
          });
}

function config_post(token,id,region_auth_type,approval_type,auth_type,pwd_type){
   axios.defaults.headers.common["token"]=token;
    axios.post('/api/config_post.html',{
     id:id,
     region_auth_type:region_auth_type,
     approval_type:approval_type,
     auth_type:auth_type,
     pwd_type:pwd_type
   }).then(res => {
            alert(res.data.msg)
          });
}


//客户锁管理员



//锁区域列表
function region_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
   return axios.post('/api/lock/region_list.html',{
     keywords:keywords,
     page:page,
     size:size
   }).then(res => {
            return res.data.list;
          });
}
function lock_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
   return axios.post('/api/lock/lock_list.html',{
     keywords:keywords,
     page:page,
     size:size
   }).then(res => {
            return res.data;
          });
}

//授权区域管理权限
//提交锁
function add_region(token,region_name,lockid){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/add_region.html',{
     region_name:region_name,
     lockid:lockid
   }).then(res => {
         return res.data;
          });
}
function auth_region(token,region_id,user_id){
   axios.defaults.headers.common["token"] = token;
   axios.post('/api/lock/auth_region.html',{
     region_id:region_id,
     user_id:user_id
   }).then(res => {
            alert(res.data.msg);
          });
}
function auth_user_list(token){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/auth_user_list.html').then(res => {
         return res.data.data;
          });
}
function seregion_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/region_list.html',{
    keywords:keywords,
    page:page,
    size:size
  }).then(res => {
         return res.data.list;
          });
}
//编辑锁区域集合
function edit_region(token,id,region_name,lockid){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/edit_region.html',{
    id:id,
    region_name:region_name,
    lockid:lockid
  }).then(res => {
        return res.data;
       });
}

//锁区域集合列表

function userpowers_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/userpowers_list.html',{
    keywords:keywords,
    page:page,
    size:size
  }).then(res => {
       return  res.data.list;
          });
}


//删除锁区域集合
function delete_region(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/delete_region.html',{
    id:id
  }).then(res => {
       return res.data;
       });
}


function edit_lockpowers(token,user_id,lockid,region_id,powers_id){
   axios.defaults.headers.common["token"] = token;
   return  axios.post('/api/user/edit_lockpowers.html',{
    user_id:user_id,
    lockid:lockid,
    region_id:region_id,
    powers_id:powers_id
  }).then(res => {
      return res.data;
          });
}


function delete_userpowers(token,user_id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/delete_userpowers.html',{
    user_id:user_id
  }).then(res => {
        return res.data;
       });
}
//所有权限集

function lockpowers_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/lockpowers_list.html',{
    keywords:keywords,
    page:page,
    size:size
  }).then(res => {
       return  res.data.list;
          });
}

//添加权限集


function add_lock_power(token,name,lockid,region_id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/add_lock_power.html',{
     name:name,
     lockid:lockid,
     region_id:region_id
  }).then(res => {
       return  res.data;
          });
}


//编辑

function lockpowers_info(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/lockpowers_info.html',{
      id:id
  }).then(res => {
       return  res.data.info;
          });
}

function edit_limt(token,id,name,lockid,region_id,user_id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/edit_lockpowers.html',{
      id:id,
      name:name,
      lockid:lockid,
      region_id:region_id,
      user_id:user_id
  }).then(res => {
       return  res.data;
          });
}

function delete_lockpowers(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/delete_lockpowers.html',{
      id:id
  }).then(res => {
       return  res.data;
          });
}
//配置个人权限
function add_user_power(token,lockid,region_id,user_id,powers_id,time){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/add_user_power.html',{
      lockid:lockid,
      region_id:region_id,
      user_id:user_id,
      powers_id:powers_id,
      time:time
  }).then(res => {
       return  res.data;
          });
}



function edit_lock(token,id,admin_id,lock_name,lock_address){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/edit_lock.html',{
      id:id,
      admin_id:admin_id,
      lock_name:lock_name,
      lock_address:lock_address
  }).then(res => {
       return  res.data;
          });
}

function delete_lock(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/lock/delete_lock.html',{
      id:id
  }).then(res => {
       return  res.data;
          });
}


//客户
function customer_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/customer_list.html',{
      keywords:keywords,
      page:page,
      size:size
  }).then(res => {
       return  res.data;
          });
}

function edit_customer(token,data){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/edit_customer.html',{
     ...data
  }).then(res => {
       return  res.data;
          });
}

function delete_powerslog(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/delete_powerslog.html',{
       id:id
  }).then(res => {
       return  res.data;
          });
}

function delete_account(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/delete_account.html',{
       id:id
  }).then(res => {
       return  res.data;
          });
}

function add_customer(token,data){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/add_customer.html',{
       ...data
  }).then(res => {
       return  res.data;
          });
}

function openlock_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/openlock_list.html',{
       keywords:keywords,
       page:page,
       size:size
  }).then(res => {
       return  res.data;
          });
}

function user_handlelog(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/user_handlelog.html',{
       keywords:keywords,
       page:page,
       size:size
  }).then(res => {
       return  res.data;
          });
}



function apply_loglist(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/apply_loglist.html',{
       keywords:keywords,
       page:page,
       size:size
  }).then(res => {
       return  res.data;
          });
}


function userapply_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/userapply_list.html',{
       keywords:keywords,
       page:page,
       size:size
  }).then(res => {
       return  res.data;
          });
}

function apply_status(token,id,status,remark){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/apply_status.html',{
       id,
       status,
       remark
  }).then(res => {
       return  res.data;
          });
}


function user_list(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('api/user/user_list.html',{
      keywords,
      page,
      size
  }).then(res => {
       return  res.data;
          });
}

function edit_user(token,param){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/edit_user.html',{
      ...param
  }).then(res => {
       return  res.data;
          });
}

function delete_user(token,id){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/user/delete_user.html',{
      id
  }).then(res => {
       return  res.data;
          });
}

function getpwd_order(token,keywords,page,size){
   axios.defaults.headers.common["token"] = token;
  return axios.post('/api/staff/getpwd_order.html',{
      keywords,
      page,
      size
  }).then(res => {
       return  res.data;
          });
}

 export{
   send_code,
   login,
   getpermiss_list,
   getmenu_list,
   getaccount_list,
   add_account,
   getcustomer_change,
   edit_account,
   permiss_list,
   depar_list,
   account_info,
   userpowers_change,
   sys_config,
   config_post,
   region_list,
   auth_region,
   auth_user_list,
   seregion_list,
   lock_list,
   add_region,
   edit_region,
   userpowers_list,
   lockpowers_list,
   delete_region,
   edit_lockpowers,
   delete_userpowers,
   add_lock_power,
   lockpowers_info,
   edit_limt,
   delete_lockpowers,
   add_user_power,
   edit_lock,
   delete_lock,
   customer_list,
   edit_customer,
   delete_powerslog,
   delete_account,
   add_customer,
   openlock_list,
   user_handlelog,
   apply_loglist,
   userapply_list,
   apply_status,
   user_list,
   edit_user,
   delete_user,
   getpwd_order
   }
